package com.dhq.myapp.util.dialog.custom

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.widget.TextView
import com.dhq.myapp.R
import com.dhq.myapp.util.dialog.DialogBuilder
import com.lxj.xpopup.core.CenterPopupView


/**
 * DESC 默认中心提示弹框
 *
 *
 * Created by admin on 2019/8/26.
 */
class DefaultCenterPopup : CenterPopupView {
    var mBuilder: DialogBuilder? = null

    constructor(context: Context) : super(context)

    constructor(builder: DialogBuilder) : super(builder.context!!) {
        this.mBuilder = builder
    }

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_center_layout
    }

    override fun onCreate() {
        super.onCreate()

        val btnConfirm: TextView
        val btnCancle: TextView
        val tvContent: TextView


        btnConfirm = findViewById<TextView?>(R.id.id_dialog_hint_confirm)
        btnCancle = findViewById<TextView?>(R.id.id_dialog_hint_cancle)
        tvContent = findViewById<TextView?>(R.id.id_dialog_hint_context)

        btnConfirm.setText(mBuilder!!.comfirmText)
        btnCancle.setText(mBuilder!!.cancleText)
        tvContent.setText(mBuilder!!.content)
        if (mBuilder!!.contentColor !== 0) {
            tvContent.setTextColor(
                mBuilder!!.context!!.getResources().getColor(mBuilder!!.contentColor)
            )
        }

        btnConfirm.setOnClickListener(OnClickListener { v: View? ->
            //确定事件
            if (mBuilder!!.comfirmListener != null) {
                mBuilder!!.comfirmListener!!.onClickListener(this)
            } else {
                dismiss()
            }
        })


        if (TextUtils.isEmpty(mBuilder!!.cancleText)) {
            btnCancle.setVisibility(GONE)
        } else {
            btnCancle.setOnClickListener(OnClickListener { v: View? ->
                //取消事件
                if (mBuilder!!.cancleListener != null) {
                    mBuilder!!.cancleListener!!.onClickListener(this)
                } else {
                    dismiss()
                }
            })
        }
    }

    override fun onShow() {
        super.onShow()
    }

    //        @Override
    //        protected int getMaxHeight() {
    //            return 200;
    //        }
    //
    //返回0表示让宽度撑满window，或者你可以返回一个任意宽度
    override fun getMaxWidth(): Int {
        return context.getResources().getDimensionPixelOffset(R.dimen.dp750_600)
    }
}